﻿using System;
using System.Linq.Expressions;
using System.Text;
using SBACN.WebSite.Code;
using SBACN.WebSite.Models;

namespace SBACN.WebSite
{
	public partial class WebLink : BasePage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			BindData();
		}

		protected void BindData()
		{
			Expression<Func<TB_OutLink, bool>> f = (p => ( p.Category == "" && !p.Status));
			Expression<Func<TB_OutLink, int>> order = (c => (c.ID));
			var resultM = DAL.DALHelper.Instance.GetList<TB_OutLink, int>(f, order, true);

			this.Map.DataSource = resultM;
			this.Map.DataBind();
		}

		protected string Second(string ID)
		{
			Expression<Func<TB_OutLink, bool>> f = (p => (p.Category == ID && !p.Status ));
			Expression<Func<TB_OutLink, int>> order = (c => (c.ID));
			var resultM = DAL.DALHelper.Instance.GetList<TB_OutLink, int>(f, order, true);

			if (resultM.Count > 0)
			{
				StringBuilder Html = new StringBuilder();
				foreach (var l in resultM)
				{
					string url = "";
					if (!l.LinkUrl.Contains("http://"))
					{
						url = "http://" + l.LinkUrl;
					}
					else
					{
						url = l.LinkUrl;
					}

					Html.Append("<p><a target='_blank' href='" + url + "'>");
					Html.Append(l.LinkName);
					Html.Append("</a></p>");
					
				}
				return Html.ToString();
			}
			else
			{
				return "";
			}

		}
	}
}